#include "playaudio.h"

#include <QProcess>
#include <QSound>
PlayAudio::PlayAudio(QObject *parent)
  : QThread(parent), state(STOP)
{

}

void PlayAudio::addFile(const QString &file)
{
  fileList.push_back(file);

}

void PlayAudio::run()
{
  while(1) {

    if (!fileList.isEmpty()) {

      QString filename = fileList.first();
      if (state == STOP) {
        state = PLAYING;
        emit toogle();
      }
      QProcess::execute("mpg123 " + filename);
      fileList.removeFirst();

      if (fileList.isEmpty() && state == PLAYING) {
        emit toogle();
        state = STOP;
      }
    }

    msleep(10);
  }
}
